import {
  FormAsyncValidateOrFn,
  FormOptions,
  FormValidateOrFn,
  ReactFormExtendedApi,
  useForm
} from '@tanstack/react-form'

// 重构后的类型
export type IFormApi<T> = ReactFormExtendedApi<
  T,
  FormValidateOrFn<T> | undefined,
  FormValidateOrFn<T> | undefined,
  FormAsyncValidateOrFn<T> | undefined,
  FormValidateOrFn<T> | undefined,
  FormAsyncValidateOrFn<T> | undefined,
  FormValidateOrFn<T> | undefined,
  FormAsyncValidateOrFn<T> | undefined,
  FormAsyncValidateOrFn<T> | undefined,
  unknown
>

type SyncValidation<T> = FormValidateOrFn<T> | undefined
type AsyncValidation<T> = FormAsyncValidateOrFn<T> | undefined

type FormConfig<T> = FormOptions<
  T,
  SyncValidation<T>,
  SyncValidation<T>,
  AsyncValidation<T>,
  SyncValidation<T>,
  AsyncValidation<T>,
  SyncValidation<T>,
  AsyncValidation<T>,
  AsyncValidation<T>,
  unknown
>

export function BmForm<T>(config: FormConfig<T>) {
  return useForm(config)
}
